import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import'rxjs/add/operator/map';
import { Park } from './park';

/*
  Generated class for the ParkDataProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class ParkDataProvider {
  private readonly baseUrl:string = 'https://api.bmob.cn/1';
  private readonly httpHeader : HttpHeaders = new HttpHeaders({
    'X-Bmob-Application-Id':'d11f9cc9857b87ecb79bc62fa506f227',
    'X-Bmob-REST-API-Key':'0f54606d923616ec5e4e43fb82379739',
    'Content-Type':'application/json'
  });

  constructor(public http: HttpClient) {
   
  }
  /**
   * 分页获取景区数据
   * @param num 
   * @param page 
   */
  getParks(num:number,page:number):Observable<Park[]>{
    let _params=new HttpParams()
    .set('limit', `${num}`)
    .set('skip', `${(page-1)*num}` );
    return this.http.get<Park[]>(`${this.baseUrl}/classes/parks`,
    {headers:this.httpHeader,params:_params}).map(_=>_['results']);
  }
}
